﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AppSocketModel;
using AppSocketService.HistoryLocation;
using BCGPSCommon;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BCGPSRESTful.Controllers.Phone.HistoryLocation
{
    /// <summary>
    /// 个人用户手机端历史定位信息
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class PhoneHistoryLocationPersonController : ControllerBase
    { 
        private readonly IHistoryLocationService historyLocationService;

        #region 构造函数
        /// <summary>
        /// 
        /// </summary>
        /// <param name="historyLocationService"></param>
        public PhoneHistoryLocationPersonController(IHistoryLocationService historyLocationService)
        {
            this.historyLocationService = historyLocationService;
        }
        #endregion

        #region 获取车辆GPS历史数据  -- 分页
        /// <summary>
        /// 获取车辆GPS历史数据 -- 分页
        /// </summary>
        /// <param name="vehicle_no">车牌号</param>
        /// <param name="imei">IMEI</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="gps_map_type">地图种类</param>
        /// <param name="desc">是否倒序</param>
        /// <param name="index">页码</param>
        /// <param name="size">记录数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<GpsInfoDto>), 200)]
        public ActionResult<PageableList<GpsInfoDto>> QueryHistoryLocationPage(string vehicle_no, string imei, DateTime? start, DateTime? end, GpsMapType? gps_map_type, bool? desc = false, int? index = 0, int? size = 20)
        {
            if (!gps_map_type.HasValue)
                gps_map_type = GpsMapType.GDMAP;
            if (!start.HasValue)
                start = DateTime.Now.AddMinutes(-10);
            if (!end.HasValue)
                end = DateTime.Now;
            if (string.IsNullOrWhiteSpace(imei))
                throw new ArgumentException("接口已经不再支持通过车牌号查询,请通过IMEI查询!");
            else
                return historyLocationService.QueryByImei(gps_map_type.Value, imei, start.Value, end.Value, desc.Value, index.Value, size.Value);
        }
        #endregion

    }
}